using Microsoft.AspNetCore.Mvc;

namespace TestApi.Controllers;

/// <summary>
/// 天气
/// </summary>
[ApiController,Route("api/[controller]"),ApiExplorerSettings(GroupName = "v1")]
public class WeatherForecastController : ControllerBase
{
    private static readonly string[] Summaries = new[]
    {
        "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
    };

    private readonly ILogger<WeatherForecastController> _logger;

    public WeatherForecastController(ILogger<WeatherForecastController> logger)
    {
        _logger = logger;
    }

    /// <summary>
    /// 获得
    /// </summary>
    /// <returns></returns>
    [HttpGet(Name = "GetWeatherForecast")]
    public IEnumerable<WeatherForecast> Get()
    {
        System.Threading.Thread.Sleep(1500);
        return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
            })
            .ToArray();
    }
    
    /// <summary>
    /// 添加
    /// </summary>
    /// <param name="model">模型</param>
    /// <returns></returns>
    [HttpPost(Name = "GetWeatherForecast")]
    public IEnumerable<WeatherForecast> Post(string agentId,[FromBody]MyClass model)
    {
        return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = model.Name+"_"+Summaries[Random.Shared.Next(Summaries.Length)]
            })
            .ToArray();
    }
    
    /// <summary>
    /// 添加
    /// </summary>
    /// <param name="model">模型</param>
    /// <returns></returns>
    [HttpPost("AddClass")]
    public IActionResult PostClass(string agentId,[FromBody]string model)
    {
        return Ok("Success");
    }
    
    /// <summary>
    /// 修改
    /// </summary>
    /// <param name="model">模型</param>
    /// <returns></returns>
    [HttpPut(Name = "GetWeatherForecast")]
    public IEnumerable<WeatherForecast> Put([FromBody]MyClass model)
    {
        return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = model.Name+"_"+Summaries[Random.Shared.Next(Summaries.Length)]
            })
            .ToArray();
    }
    
    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpDelete(Name = "GetWeatherForecast")]
    public IEnumerable<WeatherForecast> Delete([FromBody]MyClass model)
    {
        return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = model.Name+"_"+Summaries[Random.Shared.Next(Summaries.Length)]
            })
            .ToArray();
    }
    
    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="ids"></param>
    /// <returns></returns>
    [HttpDelete("delete/long")]
    public IActionResult DeleteLong([FromBody]List<long> ids)
    {
        return Ok("Delete - Success");
    }
    
    /// <summary>
    /// 我的班级
    /// </summary>
    public class MyClass
    {
        /// <summary>
        /// Id
        /// </summary>
        public long Id { get; set; } = 0;
        
        /// <summary>
        /// 名字
        /// </summary>
        public string Name { get; set; }
        
        /// <summary>
        /// 级别
        /// </summary>
        public int Level { get; set; }

        /// <summary>
        /// 是否
        /// </summary>
        public bool IsStatus { get; set; } = false;
        
        /// <summary>
        /// 枚举
        /// </summary>
        public OrderStatus Order { get; set; }

        /// <summary>
        /// 班长
        /// </summary>
        public MyStudent Student { get; set; }
        
        /// <summary>
        /// 学生
        /// </summary>
        public List<MyStudent> List { get; set; }
        
        /// <summary>
        /// ArrayString
        /// </summary>
        public List<string> ListStr { get; set; }
        
        /// <summary>
        /// ArrayInt
        /// </summary>
        public List<int> ListInt { get; set; }
        
        /// <summary>
        /// ArrayLong
        /// </summary>
        public List<long> ListLong { get; set; }
        
    }
    
    /// <summary>
    /// 学生信息
    /// </summary>
    public class MyStudent
    {
        /// <summary>
        /// 名字
        /// </summary>
        public string Name { get; set; }
        
        /// <summary>
        /// 年纪
        /// </summary>
        public int Level { get; set; }

        /// <summary>
        /// 日期
        /// </summary>
        public DateTime Time { get; set; } = DateTime.Now;
    }

    public enum OrderStatus
    {
        Pay=1,
        Success=2
    }
}